package com.think.teaching.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.think.teaching.mapper.QuestionSelectionMapper;
import com.think.teaching.model.ExamTest;
import com.think.teaching.model.QuestionSelection;
import com.think.teaching.service.QuestionSelectionService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 选择题选项 服务实现类
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
@Service
public class QuestionSelectionServiceImpl extends BaseServiceImpl<QuestionSelectionMapper, QuestionSelection> implements QuestionSelectionService {

	@Override
	public QuestionSelection AddQuestionSelection(QuestionSelection questionSelection) {
		if (this.save(questionSelection)) {
			return questionSelection;
		}
		return null;
	}


	@Override
	public QuestionSelection UpdateQuestionSelection(QuestionSelection questionSelection) {
		if (this.updateById(questionSelection)) {
			return questionSelection;
		}
		return null;
	}

	@Override
	public QuestionSelection GetQuestionSelection(Integer id) {
		QueryWrapper<QuestionSelection> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", id).eq("state", 1).ne("delflag", 1);
		return getOne(queryWrapper);
	}

	@Override
	public QuestionSelection SetQuestionSelectionState(Integer id, Integer state) {
		UpdateWrapper<QuestionSelection> queryWrapper = new UpdateWrapper<>();
		queryWrapper.eq("id", id).ne("delflag", 1).set("state", state);
		this.update(queryWrapper);
		return getById(id);
	}
	
	/**
	 * 删除和指定的questionId相关的选项
	 * @param questionId
	 * @return
	 */
	public Boolean DeleteRecordsByPaperId(Integer questionId) {
		UpdateWrapper<QuestionSelection> queryWrapper = new UpdateWrapper<QuestionSelection>();
		queryWrapper.eq("question_id", questionId).set("delflag", 1);
		return this.update(queryWrapper);
	}

}
